/********************************************************
 *  ██████╗  ██████╗████████╗██╗
 * ██╔════╝ ██╔════╝╚══██╔══╝██║
 * ██║  ███╗██║        ██║   ██║
 * ██║   ██║██║        ██║   ██║
 * ╚██████╔╝╚██████╗   ██║   ███████╗
 *  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
 * Geophysical Computational Tools & Library (GCTL)
 *
 * Copyright (c) 2023  Yi Zhang (yizhang-geo@zju.edu.cn)
 *
 * GCTL is distributed under a dual licensing scheme. You can redistribute 
 * it and/or modify it under the terms of the GNU Lesser General Public 
 * License as published by the Free Software Foundation, either version 2 
 * of the License, or (at your option) any later version. You should have 
 * received a copy of the GNU Lesser General Public License along with this 
 * program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * If the terms and conditions of the LGPL v.2. would prevent you from using 
 * the GCTL, please consider the option to obtain a commercial license for a 
 * fee. These licenses are offered by the GCTL's original author. As a rule, 
 * licenses are provided "as-is", unlimited in time for a one time fee. Please 
 * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget 
 * to include some description of your company and the realm of its activities. 
 * Also add information on how to contact you by electronic and paper mail.
 ******************************************************/

#include "refellipsoid.h"

gctl::refellipsoid::refellipsoid(/* args */){}

gctl::refellipsoid::refellipsoid(refellipsoid_type_e refellipsoid)
{
    set(refellipsoid);
}

gctl::refellipsoid::refellipsoid(double R, double r, bool flat)
{
    set(R, r, flat);
}

gctl::refellipsoid::~refellipsoid(){}

void gctl::refellipsoid::set(refellipsoid_type_e refellipsoid)
{
   if (refellipsoid == Earth) {r_ = R_ = GCTL_Earth_Radius;}
   else if (refellipsoid == Moon) {r_ = R_ = GCTL_Moon_Radius;}
   else if (refellipsoid == Mars) {r_ = R_ = GCTL_Mars_Radius;}
   else if (refellipsoid == WGS84) {r_ = GCTL_WGS84_PoleRadius; R_ = GCTL_WGS84_EquatorRadius;}
   else if (refellipsoid == Ardalan2010) {r_ = GCTL_Mars_Ardalan2010_PoleRadius; R_ = GCTL_Mars_Ardalan2010_EquatorRadius;}
   else throw std::invalid_argument("Invalid reference system type for gctl::refellipsoid::set(...)");
}

void gctl::refellipsoid::set(double R, double r_or_flat, bool is_flat)
{
    R_ = R;
    if (is_flat) r_ = R_*(1 - 1/r_or_flat);
    else r_ = r_or_flat;
}

double gctl::refellipsoid::radis_at(double lati)
{
    return ellipse_radius_2d(R_, r_, lati*M_PI/180.0, 0.0);
}